import json
import logging
import os

from coin2.support.product_info.spot_ftx_v1 import convert_coin1_constants as convert_coin1_spot_constants
from coin2.support.product_info.futures_ftx_v1 import convert_coin1_constants as convert_coin1_futures_constants


pi_file = 'data/coin2/product_info/Spot.Ftx.v1.json'
futures_pi_file = 'data/coin2/product_info/Futures.Ftx.v1.json'
with open(pi_file) as f:
  spot_static_constants = convert_coin1_spot_constants(json.load(f)['product_infos'])
with open(futures_pi_file) as f:
  futures_static_constants = convert_coin1_futures_constants(json.load(f)['product_infos'])
spot_dynamic_constants = {}
futures_dynamic_constants = {}
if int(os.getenv('USE_DYNAMIC_SYMBOL', 0)):
  try:
    from coin2.support.product_info.spot_ftx_v1 import gen_coin1_constants
    spot_dynamic_constants = gen_coin1_constants()
    from coin2.support.product_info.futures_ftx_v1 import gen_coin1_constants
    futures_dynamic_constants = gen_coin1_constants()
  except Exception as e:
    logging.error('Failed to use ftx dynamic symbols! %s', e)

base_currency_list = list(set(
    spot_static_constants.get('base_currency_list', []) +
    spot_dynamic_constants.get('base_currency_list', []) +
    futures_static_constants.get('base_currency_list', []) +
    futures_dynamic_constants.get('base_currency_list', [])
))
quote_currency_list = list(set(
    spot_static_constants.get('quote_currency_list', []) +
    spot_dynamic_constants.get('quote_currency_list', []) +
    futures_static_constants.get('quote_currency_list', []) +
    futures_dynamic_constants.get('quote_currency_list', [])
))
currency_list = list(set(
    ['SRM_LOCKED'] +
    spot_static_constants.get('currency_list', []) +
    spot_dynamic_constants.get('currency_list', []) +
    futures_static_constants.get('currency_list', []) +
    futures_dynamic_constants.get('currency_list', [])
))
symbol_list = list(set(
    spot_static_constants.get('symbol_list', []) +
    spot_dynamic_constants.get('symbol_list', [])
))
